package edu.nuist.javaProjct.view;

import edu.nuist.javaProjct.dao.StudentDatasourceDao;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DeleteDataModel {
    public JPanel deleteDataModel;
    private JTextField deleteUuidField;
    private JButton deleteBtn;

    private final StudentDatasourceDao studentBasicDao=new StudentDatasourceDao();

    public DeleteDataModel() {
        deleteBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String studentUUID = deleteUuidField.getText();
                if (studentUUID.equals("")){
                    JOptionPane.showMessageDialog(deleteDataModel, "请输入正确的学生信息", "请注意",JOptionPane.WARNING_MESSAGE);
                    return ;
                }

                int result=studentBasicDao.deleteData(studentUUID);
                if (result==1){
                    JOptionPane.showMessageDialog(deleteDataModel, "数据删除成功", "成功",JOptionPane.PLAIN_MESSAGE);
                }else{
                    JOptionPane.showMessageDialog(deleteDataModel, "请输入正确的学生信息", "请注意",JOptionPane.WARNING_MESSAGE);
                }

            }
        });
    }
}
